﻿using NB.MGJ.FrameWork;
using NB.MGJ.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NB.MGJ.Service.CodeManage
{
    /// <summary>
    /// dy
    /// 2017年9月22日
    /// </summary>
    public class CardService
    {
        public BaseRepository _baseRepository = new BaseRepository();
        #region 获取单数据
        public CodeManage_Card GetModel(int ID)
        {
            string sql = string.Format(@" select top 1 CodeManage_Card.ID, CodeManage_Card.LabelImgUrl, CodeManage_Card.ProductImgUrl,
          CodeManage_Card.CustomerCard, CodeManage_Card.Phone, CodeManage_Card.LikeCard, CodeManage_Card.Title, CodeManage_Card.ProdoctBrand,CodeManage_Card.BatchID,
          (select top 1 EnterpriseName from Organization_Enterprise where ID=CodeManage_GenCodeBatch.EnterpriseId) EnterpriseName,
          (select top 1 ProductName from Product_Product where ID=CodeManage_GenCodeBatch.ProductId) ProductName
          from CodeManage_Card left join CodeManage_GenCodeBatch on CodeManage_Card.BatchId=CodeManage_GenCodeBatch.ID  where BatchID={0} ", ID);
            return _baseRepository.ExecuteSql<CodeManage_Card>(sql);
        }
        #endregion

        #region 增加
        public int Add(CodeManage_Card model)
        {
            return _baseRepository.Insert<CodeManage_Card>(model);
        }
        #endregion

        #region 修改
        public int Update(CodeManage_GenCode model)
        {
            string _sql_1 = string.Format("UPDATE CODEMANAGE_GENCODE SET Query_Result_Content='{0}',Query_Tel_Content='{1}',Query_Message_Content='{2}',LabelImage='{3}' WHERE ID = {4}", model.Query_Result_Content, model.Query_Tel_Content, model.Query_Message_Content,model.LabelImage,model.ID);
            string _sql_2 = string.Format("UPDATE CODEMANAGE_CARD SET ProductImgUrl='{0}',CardType='{1}',Title='{2}',ProdoctBrand='{3}',EnterpriseUse='{4}' where ID={5}",model.ProductImgUrl,model.CardType,model.Title,model.ProdoctBrand,model.EnterpriseUse,model.CardID);
            string _sql = _sql_1 + ";" + _sql_2;
            return _baseRepository.ExecuteSql<int>(_sql);
        }
        #endregion
    }
}
